<template>
  <page-body>
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center sendPost_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub sendPost_fd0_0'>
          <view class='flex flex-wrap align-center sendPost_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  sendPost_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-center justify-end sendPost_fd0_0_c0 ' @click.stop="submit">
            <button class='sendPost_fd0_0_c1_c0'>发布</button>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout sendPost_flex_1">
        <view class='flex flex-wrap sendPost_fd1_0'>
          <textarea class='flex sendPost_input_fd1_0' :placeholder="'聊聊你的想法'" :adjust-position='true' :maxlength="240"
            :show-num='true' placeholder-style="color:#999;font-size:28rpx" v-model="title" />
          <template>
            <view class='flex flex justify-end sendPost_numberfd1_0_c0'>
              <text>{{title.length}}</text>
              <text>/</text>
              <text>240</text>
            </view>
          </template>
        </view>
        <view class="flex justify-between padding-sm solids-bottom" style="padding-bottom: 40rpx;">
          <view class="text-333">上传类型</view>
          <view class=" flex align-center">
            <view class="flex align-center margin-right-sm" @click.stop="chooseType(1)">
              <image class="chooseIcon" v-if="postType!=1" :src='STATIC_URL+"16.png"' mode="aspectFill"></image>
              <image class="chooseIcon" v-else :src='STATIC_URL+"37.png"' mode="aspectFill"></image>
              <view>图片</view>
            </view>
            <view class="flex align-center margin-right-sm" @click.stop="chooseType(2)">
              <image class="chooseIcon" v-if="postType!=2" :src='STATIC_URL+"16.png"' mode="aspectFill"></image>
              <image class="chooseIcon" v-else :src='STATIC_URL+"37.png"' mode="aspectFill"></image>
              <view>视频</view>
            </view>
          </view>
        </view>
        <view class='flex flex-wrap align-center' v-if="postType==1">
          <benben-images-upload ref="benbenImagesUploadfd1_1_c0" :img-list.sync="imgList" :img-ids.sync="imgIds"
            :maxlength="9">
            <template #content="{ num, maxlength, isShow, imgList }">
              <view class="flex flex-wrap align-start flex sendPost_fd1_1_c0">

                <view v-for="(image, index) in imgList" :key="index" class='flex position-relative sendPost_fd1_1_c00'>
                  <text class='fu-iconfont2 position-absolute sendPost_fd1_1_c000'
                    @tap.stop="$refs.benbenImagesUploadfd1_1_c0.delImage(index)">&#xE8E7;</text>
                  <image class='sendPost_fd1_1_c001' @tap.stop="$refs.benbenImagesUploadfd1_1_c0.previewImage(index)"
                    mode="aspectFit" :src='image'></image>
                </view>

                <image class='sendPost_fd1_1_c01' @tap.stop="$refs.benbenImagesUploadfd1_1_c0.manyChooseImage()"
                  v-if="isShow" mode="aspectFit" :src='STATIC_URL+"178.jpg"'></image>

              </view>
            </template>
          </benben-images-upload>
        </view>
        <view class='flex flex-wrap align-center' v-if="postType==2">
          <benben-video-upload ref="upload1688641081458" :src.sync="video" :video-id.sync="video" :name.sync="videoName"
            isShowClean='true'>
            <template v-slot="{src, poster}">
              <view class='flex position-relative sendPost_fd1_1_c0'>
                <image class='sendPost_fd1_1_c001' mode="aspectFill" @tap="$refs.upload1688641081458.previewVideo()"
                  :src="src?src + '?x-oss-process=video/snapshot,t_1000,m_fast':STATIC_URL+'178.jpg'"></image>

                <text class='fu-iconfont2 position-absolute sendPost_fd1_1_c01'
                  @tap="$refs.upload1688641081458.delVideo()" v-if="src">&#xE8E7;</text>

              </view>
            </template></benben-video-upload>
        </view>

      </view>

      <!---flex布局flex布局结束-->


    </view>
  </page-body>
</template>
<script>
  export default {
    components: {},


    data() {
      return {
        "title": "",
        "imgIds": "",
        "imgList": [],
        postType: '1',
        video: '',
        videoName: ''
      };
    },
    computed: {

    },
    watch: {},
    onLoad(options) {

    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      chooseType(type) {
        this.postType = type
      },
      submit() {
        console.log(this.video)
        if (!this.title) {
          this.$message.info('请输入标题')
          return
        }
        if (this.postType == 1) {
          this.video = ''
          if (this.imgList.length == 0) {
            this.$message.info('请上传图片')
            return
          }
        } else {
          this.imgList = []
          this.imgIds = ''
          if (!this.video) {
            this.$message.info('请上传视频')
            return
          }
        }
        this.$api.dbPost(global.apiUrls.post6458a2d0458b5, {
          title: this.title,
          postType: this.postType == 1 ? 'image' : 'video',
          image: this.imgList.join(','),
          video: this.video
        }).then(res => {

          if (res.data.code == 1) {
            this.$message.info('发布成功')
            setTimeout(result => {
              uni.navigateBack()
            }, 800)
          } else {
            this.$message.info(res.data.msg)
          }
        })
      },
    }
  };
</script>
<style lang="scss" scoped>
  .chooseIcon {
    width: 32rpx;
    height: 32rpx;
    margin-right: 16rpx;
  }

  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #F8F8F8;
    background-size: 100% auto;
  }

  .sendPost_flex_0 {
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .sendPost_fd0_0_c1_c0 {
    background: #5ECA71;
    border-radius: 10rpx 10rpx 10rpx 10rpx;
    width: 112rpx;
    line-height: 46rpx;
    font-size: 24rpx;
    color: #fff;
    height: 46rpx;
  }

  .sendPost_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .sendPost_fd0_0_c0 {
    width: 120rpx;
  }

  .sendPost_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .sendPost_flex_1 {
    background: var(--benbenbgColor1);
    width: 702rpx;
    margin: 24rpx auto 0rpx auto;
    background-size: 100% auto;
    border-radius: 16rpx;
  }

  .sendPost_fd1_1_c01 {
    width: 160rpx;
    height: 160rpx;
    margin: 0rpx 24rpx 24rpx 0rpx;
  }

  .sendPost_fd1_1_c001 {
    width: 160rpx;
    height: 160rpx;
  }

  .sendPost_fd1_1_c000 {
    top: 0rpx;
    right: 0rpx;
    z-index: 1;
    color: #ff5536;
  }

  .sendPost_fd1_1_c00 {
    margin: 0rpx 24rpx 24rpx 0rpx;
  }

  .sendPost_fd1_1_c0 {
    width: 702rpx;
    padding: 24rpx 0rpx 24rpx 24rpx;
  }

  .sendPost_numberfd1_0_c0 {
    width: 100%;
    font-size: 24rpx;
    color: var(--benbenFontColor1);
    line-height: 46rpx;
    font-weight: 400;
  }

  .sendPost_input_fd1_0 {
    width: 100%;
    height: 140rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #333;
    white-space: pre-wrap;
  }

  .sendPost_fd1_0 {
    background: #F8F8F8;
    width: 654rpx;
    border-radius: 16rpx;
    padding: 16rpx;
    margin: 24rpx auto 32rpx auto;
  }
</style>
